package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportRegistrationSignin;
import cn.stylefeng.guns.modular.transport.mapper.TransportRegistrationSigninMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportRegistrationSigninParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportRegistrationSigninResult;
import  cn.stylefeng.guns.modular.transport.service.TransportRegistrationSigninService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 临时工签到 服务实现类
 * </p>
 *
 * @author 翟登巍
 * @since 2024-03-05
 */
@Service
public class TransportRegistrationSigninServiceImpl extends ServiceImpl<TransportRegistrationSigninMapper, TransportRegistrationSignin> implements TransportRegistrationSigninService {

    @Override
    public void add(TransportRegistrationSigninParam param){
        TransportRegistrationSignin entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportRegistrationSigninParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportRegistrationSigninParam param){
        TransportRegistrationSignin oldEntity = getOldEntity(param);
        TransportRegistrationSignin newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportRegistrationSigninResult findBySpec(TransportRegistrationSigninParam param){
        return null;
    }

    @Override
    public List<TransportRegistrationSigninResult> findListBySpec(TransportRegistrationSigninParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportRegistrationSigninParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportRegistrationSigninParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportRegistrationSignin getOldEntity(TransportRegistrationSigninParam param) {
        return this.getById(getKey(param));
    }

    private TransportRegistrationSignin getEntity(TransportRegistrationSigninParam param) {
        TransportRegistrationSignin entity = new TransportRegistrationSignin();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
    @Override
    public TransportRegistrationSigninResult find(TransportRegistrationSigninParam param) {
        return this.baseMapper.find(param);
    }
}
